from typing import AsyncIterator, Any

import scrapy


class A生产者Spider(scrapy.Spider):
    name = "生产者"

    async def start(self):
        yield scrapy.Request(url="https://quotes.toscrape.com/", callback=self.parse)

    def parse(self, response):
        items = response.xpath('//div[@class="quote"]')
        for item in items:
            yield {
                "author":item.xpath('.//small[@class="author"]/text()').get().strip(),
                "content":item.xpath('.//span[@class="text"]/text()').get().strip()[1:-1],
                "tags":item.xpath('.//a[@class="tag"]/text()').getall(),
            }

        next_page = response.xpath('//li[@class="next"]/a/@href').get()
        if next_page:
            yield response.follow(url=next_page)